package com.baizan.daka.ui.presenter

import com.baizan.daka.base.BasePresenter
import com.baizan.daka.mvp.model.MeModel
import com.baizan.daka.mvp.model.UserModel
import com.baizan.daka.mvp.model.bean.BankCardInfoBean
import com.baizan.daka.mvp.model.bean.UserInfoBean
import com.baizan.daka.mvp.model.bean.UserPackageDes
import com.baizan.daka.rx.Subscriber.CommonSubscriber
import com.baizan.daka.showToast
import com.baizan.daka.ui.contract.MeContract

class MePresenter(val mView: MeContract.View) : BasePresenter(),
    MeContract.Presenter {


    private val userModel: UserModel by lazy {
        UserModel()
    }
    private val meModel: MeModel by lazy {
        MeModel()
    }


    override fun getUserInfo() {
        mView.showLoadingDialog()
        userModel.getUserInfo()
            .subscribe(object : CommonSubscriber<UserInfoBean>(compositeDisposable) {

                override fun onCallNext(t: UserInfoBean?) {
                    mView.loadSuccess(t!!)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })
    }

    override fun getBankInfo() {
        mView.showLoadingDialog()
        meModel.getBankCard()
            .subscribe(object :CommonSubscriber<BankCardInfoBean>(compositeDisposable){

                override fun onCallNext(t: BankCardInfoBean?) {
                    t?.let {
                        mView.getBankInfoSuccess(it)
                    }?:let {
                        mView.getBankInfoFail()
                    }

                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    mView.getBankInfoFail()
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })
    }

    override fun loaduserPackageDes() {
        mView.showLoadingDialog()
        meModel.userPackageDes()
            .subscribe(object :
                CommonSubscriber<UserPackageDes>(compositeDisposable) {

                override fun onCallNext(t: UserPackageDes?) {
                    mView.loaduserPackageDesSuccess(t!!)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    mView.loadUserPackageDesFail(e)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })
    }


}

